package com.xlt.activiti.one;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.repository.ProcessDefinitionQuery;

import java.util.List;

public class ActivitiDeploymentDeleteFore {

    public static void deploymentDeleteFore(String key){
        // 1.得到processEngine对象
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        // 2.获取repositoryService
        RepositoryService repositoryService = processEngine.getRepositoryService();

        // 3.查询流程定义
        ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();

        // 4.遍历查询结果
        List<ProcessDefinition> list = processDefinitionQuery.
                processDefinitionKey(key).orderByProcessDefinitionVersion().desc().list();
        if(list!=null && list.size()>0){

            repositoryService.deleteDeployment(list.get(0).getDeploymentId(),true);
        }
    }
}
